package com.zhiyuancode.conf;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 杨志远[OF2551]
 * company qianmi.com
 * Date    2018-11-29
 */
public enum Scope {
    //    prototype,request,session,singleton
    PROTOTYPE("prototype"),
    REQUEST("request"),
    SESSION("session"),
    SINGLETON("singleton");

    private String name;

    private static Map<String, Scope> scopeMap = new HashMap<>();

    static {
        Arrays.stream(Scope.values())
                .forEach(en -> {
                    scopeMap.put(en.name(), en);
                    scopeMap.put(en.name, en);
                });
    }

    Scope(String name) {
        this.name = name;
    }

    public static Scope genetateScope(String name) {
        Scope scope = scopeMap.get(name);
        return scope == null ? Scope.SINGLETON : scope;
    }

    public static void main(String[] args) {
        Scope scope = scopeMap.get("PROTOTYPE");
        System.out.println(scope);
    }
}
